package com.spark.text

import org.apache.spark.sql.SparkSession

object Test {

  def main(args: Array[String]): Unit = {
    val spark = SparkSession
      .builder
      .master("local")
      .appName("HdfsTest")
      .getOrCreate()

    val filePAth = args(0)
//    val rdd = spark.sparkContext.textFile(filePAth)
//    val lines = rdd.flatMap(x => x.split(" "))
//      .map(x =>(x,1))
//      .reduceByKey((a,b) =>(a+b))
//      .collect().toList
    import spark.implicits._
    val dataset = spark.read.textFile(filePAth)
      .flatMap(x => x.split(" "))
      .map(x =>(x,1))
      .groupBy("_1")
      .count()
      .show()
  }
}
